package demo3;

import java.util.Scanner;

public class Practise7 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[][] daAn = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                daAn[i][j] = in.nextInt();
            }
        }
        int ret = 0;
        for (int i = 0; i < n; i++) {
            int len = in.nextInt();
            int[] answer = new int[len];
            for (int j = 0; j < len; j++) {
                answer[j] = in.nextInt();
            }
            int j = 0;
            boolean flag = true;
            for (j = 0; j < m; j++) {
                int k = 0;
                for (k = 0; k < len; k++) {
                    if(answer[k] == daAn[i][j]) {//答案正确
                        break;
                    }
                }
                if(k == len) {//表示到尾了，都没有结束
                    flag = false;
                }
            }
            if(flag && j == m) {
                ret += 2;
            }
        }
        System.out.println(ret);
    }
}
